Skip to content

Conversation

@mrudatsprint
Copy link
Contributor

DataStoreStorage replaces the deprecated SharedPreferencesStorage as a way to store tokens.

@mrudatsprint mrudatsprint requested a review from Copilot December 12, 2025 01:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR deprecates SharedPreferencesStorage in favor of the new DataStoreStorage implementation for token persistence. The change aligns with modern Android development practices by adopting Jetpack DataStore.

Key Changes:

  • Introduced DataStoreStorage class using Jetpack DataStore for persistence
  • Deprecated SharedPreferencesStorage with a warning-level annotation
  • Updated sample app activities to use the new DataStoreStorage

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
SharedPreferencesStorage.kt Added deprecation annotation directing users to DataStoreStorage
DataStoreStorage.kt New storage implementation using Jetpack DataStore with synchronous API wrapping coroutines
library/build.gradle.kts Added DataStore preferences dependency (version 1.2.0)
TokenActivity.kt Replaced SharedPreferencesStorage with DataStoreStorage in initialization
LoginActivity.kt Replaced SharedPreferencesStorage with DataStoreStorage in initialization
README.md Updated documentation to reference DataStoreStorage instead of SharedPreferencesStorage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 33 to 35
return runBlocking {
context.dataStore.data.first()[prefKey]
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR (Application Not Responding) errors. Consider making the Storage interface suspend-based or providing async alternatives, as DataStore is designed to be used with coroutines asynchronously.

Copilot uses AI. Check for mistakes.
Comment on lines 47 to 51
runBlocking {
context.dataStore.edit { settings ->
settings[prefKey] = content.toString()
}
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR errors. Consider making the Storage interface suspend-based or providing async alternatives.

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 66
runBlocking {
context.dataStore.edit { settings ->
settings.remove(prefKey)
}
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using runBlocking on the main thread for storage operations can cause UI freezes and ANR errors. Consider making the Storage interface suspend-based or providing async alternatives.

Copilot uses AI. Check for mistakes.
*/
@Deprecated(
message = "Use DataStoreStorage instead",
replaceWith = ReplaceWith("DataStoreStorage"),
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReplaceWith should include the full qualified name or import statement. Use ReplaceWith(\"DataStoreStorage\", \"io.fusionauth.mobilesdk.storage.DataStoreStorage\") to ensure IDEs can properly auto-import when applying the replacement.

Suggested change
replaceWith = ReplaceWith("DataStoreStorage"),
replaceWith = ReplaceWith("DataStoreStorage", "io.fusionauth.mobilesdk.storage.DataStoreStorage"),

Copilot uses AI. Check for mistakes.
@mrudatsprint mrudatsprint requested a review from Copilot December 13, 2025 18:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AuthorizationManager.clearState()
lifecycleScope.launch {
AuthorizationManager.clearState()
}
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signOut() method finishes with starting a new activity, but the clearState() operation is async and may not complete before the activity transition. Consider awaiting the clearState() call completion before starting the new activity.

Copilot uses AI. Check for mistakes.
*/
override suspend fun get(key: String): String? {
val prefKey = stringPreferencesKey(key)
return context.dataStore.data.first()[prefKey]
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .first() on DataStore.data will block until the first value is available. For better performance and error handling, consider using .map { it[prefKey] }.first() which can provide more granular control over the data flow.

Suggested change
return context.dataStore.data.first()[prefKey]
return context.dataStore.data.map { it[prefKey] }.first()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants